#ifndef __DEEPZOOMIMAGETILESOURCE_H__
#define __DEEPZOOMIMAGETILESOURCE_H__

#include "expat/expat.h"
#include "multiscaletilesource.h"
#include "DeepZoomImageDLL.h"

namespace DeepZoomImage
{
	class MultiScaleSubImage;

	class DEEP_ZOOM_IMAGE_DLL DeepZoomImageTileSource : public MultiScaleTileSource
	{
	public:
		DeepZoomImageTileSource ();
		virtual ~DeepZoomImageTileSource ();

		void loadRes();
		void unloadRes();
		bool SetSourcePath( const char * sourcePath );
		const char * GetSourcePath();

		bool IsCollection () { return m_bIsCollection; }
		int GetMaxLevel () { return max_level; }

		MultiScaleSubImage * GetSubImage (guint index);
		guint GetSubImageCount ();

		bool GetTileLayer (int level, int x, int y, void **tile);
		bool IsLoaded () { return m_bIsLoaded; }
		bool IsParsed () { return m_bParsed; }

		void SetServerFormat (const char *server_format);
		void SetFormat (const char *format);

		char *GetServerFormat () { return server_format; }

		void XmlWrite (char *buffer, gint32 offset, gint32 n);
		int readXMLFile( const char *fileName );

	protected:	
		bool m_bIsCollection;
		bool m_bIsLoaded;
		bool m_bParsed;

		char *format;
		char *server_format;
		GPtrArray *display_rects;
		GPtrArray *subimages;
		XML_Parser parser;
		int max_level;
		char * m_pXMLBuffer;
		char * m_pSourcePath;

		void Init ();
	};
};
#endif /* __DEEPZOOMIMAGETILESOURCE_H__ */
